﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SynoManager.DownloadStation.Plugins
{
    public partial class CredentialForm : Form
    {
        public CredentialForm()
        {
            InitializeComponent();
            this.Icon = Icon.FromHandle(Properties.Resources.key.GetHicon());
        }

        private SiteCredential current;
        public SiteCredential Credentials
        {
            get
            {
                if (current == null)
                {
                    current = new SiteCredential(hostTextBox.Text, usernameTextBox.Text, passwordTextBox.Text);
                }
                else
                {
                    current.Host = hostTextBox.Text;
                    current.Username = usernameTextBox.Text;
                    current.Password = passwordTextBox.Text;
                }
                return current;
            }
            set
            {
                hostTextBox.Text = value.Host;
                usernameTextBox.Text = value.Username;
                passwordTextBox.Text = value.Password;
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(hostTextBox.Text))
            {
                MessageBox.Show(this, "Please enter a hostname");
                return;
            }

            if (String.IsNullOrEmpty(usernameTextBox.Text))
            {
                MessageBox.Show(this, "Please enter a username");
                return;
            }

            DialogResult = DialogResult.OK;
        }

    }
}
